//Chip HR8P506
//Files Encoded UTF-8

#include "App_Main.h"



void App_Init(void)
{	
	uint16_t temp;
	
    GPIOConfig();
    //SystemConfig();
    FanCtrlInit();

//    SystemConfig();
	UI_Init();
	ADInit();
	Key_init();
	Flash_Read();
	NT_Init();
   	Factory_main();
}

void App_Main(void)
{
	int32_t temp = 0;
	
	if (key_mset_state == 0)
	{
		temp = Temp_Param.oven;
		if(UI_System.Grill_Unit == Unit_C)
		{
			temp = F_Convert_C(temp);
		}
		UI_Show(temp);
	}
	else if (key_mset_state == 1)
	{
		if(RTD[1].status != Pt_Normal)
		{
			key_mset_state = 0;
			pro_Show_Count = 0;
			Keyboard1_Show_Count = 0;
			NT_Shine_Stop();
		}
		else
		{
			temp = Temp_Param.probe1;
			if(UI_System.Grill_Unit == Unit_C)
			{
				temp = F_Convert_C(temp);
			}
		}
		UI_Show(temp);
	}
	else if (key_mset_state == 2)
	{
		if(RTD[2].status != Pt_Normal)
		{
			key_mset_state = 0;
			pro_Show_Count = 0;
			Keyboard1_Show_Count = 0;
			NT_Shine_Stop();
		}
		else
		{
			temp = Temp_Param.probe2;
			if(UI_System.Grill_Unit == Unit_C)
			{
				temp = F_Convert_C(temp);
			}
		}
		UI_Show(temp);
	}
	SwitchKey();
	KeyDetection();

	if (Switch_State == Temp_Shutoff) FanCtrlStop();
	else
	{
		TempADC_Main();
		FanCtrlStart();
	}
	HeatingFanCtrl();
	IgniterCtrl();
	ExhaustFanCtrl();
	
	WDT_Clear();
	NT_Main();
}

//Tick 2ms
void SysTick_IRQHandler(void)
{
    static uint16_t count;
	static uint16_t count_1s;

    switch_clock();
    Key_Clock();
	Tube_Clock();
    ADC_Clock();
    
    //Tick 10ms
    count++;
    if(count >= 5)
    {
        count = 0;
        FanCtrlClock();
        // Buzzer_clock();
		if(Shutdown_CountDown >= 1) Shutdown_CountDown++;
    }
	count_1s++;
	if(count_1s >= 150)
	{
		count_1s = 0;
		UI_Ver();
	}
}
